package org.example.design.command.test2.drawer;

import org.example.design.command.test2.command.MacroCommand;

import java.awt.*;

/**
 * @author huangshen
 * @version 0
 * @description 绘制对象实现类
 * @since 2022/2/14 13:47
 */
public class DrawCanvas extends Canvas implements Drawable {

    private Color color = Color.red;
    /**
     * 要绘制的圆点的半径
     */
    private int radius = 6;
    /**
     * 命令的历史记录
     */
    private MacroCommand history;

    public DrawCanvas(int width, int height, MacroCommand history) {
        setSize(width,height);
        setBackground(Color.white);
        this.history = history;
    }

    @Override
    public void paint(Graphics g) {
        history.execute();
    }

    /**
     * 绘制
     *
     * @param x X坐标
     * @param y Y坐标
     */
    @Override
    public void draw(int x, int y) {
        Graphics g = getGraphics();
        g.setColor(color);
        g.fillOval(x - radius, y - radius, radius * 2, radius * 2);
    }
}
